<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends MY_Controller {
	
	public function __construct(){
		parent::__construct();
	}
	
		
	public function checkLogin(){
		$this->load->library('session');
		$uid = $this->session->userdata('userid');
		if($uid){
			$this->sucJson(['msg'=>'已登录']);
		}else{
			$this->errJson('未登录');
		}
	}
	
	public function login(){
		$username = $this->input->post('username');
		$password = $this->input->post('password');
		$this->load->model('user_model');
		$re = $this->user_model->login($username,$password);
		if(empty($re)){
			$this->errJson('账户密码输入错误');	
		}else{
			$this->load->library('session');
			$this->session->set_userdata('userid', $re[0]['classid']);
			$this->sucJson(['msg'=>'登录成功']);
		}
		
	}
	
	public function register(){
		$data['username'] = $this->input->post('username');
		$data['password']  = $this->input->post('password');
		$data['tel']  = $this->input->post('tel');
		$data['plate']  = $this->input->post('plate');
		$this->load->model('user_model');
		$b = $this->user_model->register($data);
		if($b){
			$this->sucJson(['msg' => "username = ".$username]);
		}else{
			$this->errJson('注册失败');	
		}
		
	}
	
}
?>